// components/request/request.js
const app = getApp()
Component({

  options: {
    styleIsolation: 'apply-shared'
  },

  /**
   * 组件的属性列表
   */
  properties: {
    // 类型：my、received
    type: {
      type: String,
      value: 0
    },
    request: {
      type: Object,
      value: {}
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    displayTime: '',
    displayStatus: '',
    isToSee: false,
    operates: null
  },

  lifetimes: {
    attached () {
      const type = this.data.type
      const request = this.data.request
      // 是否待查看
      let isToSee = request.tosee === 1
      // 请求的状态
      let displayStatus = null
      if (type === 0) {
        displayStatus = request.status === 0
          ? '等待对方回应'
          : request.status === 1 ? '对方已接受，点击查看' : '对方已拒绝'
      } else {
        displayStatus = request.status === 0
          ? '等待对方回应'
          : request.status === 1 ? '对方已采纳您的线索，点击查看' : '对方未采纳您的线索'
      }
      this.setData({
        displayStatus,
        isToSee,
        displayTime: app.formatDate(request.create, 'time')
      })
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 打开请求对象（公告）详情
     */
    bindRequest () {
      const request = this.data.request
      wx.navigateTo({
        url: `/pages/detail/detail?id=${request.notice_id}`
      })
    }
  }
})
